﻿
namespace VisitorsApp.Web.DomainServices
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using VisitorsApp.Web.EF;


    // Implements application logic using the EroticDatabaseEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class EroticDomainService : LinqToEntitiesDomainService<EroticDatabaseEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'aspnet_Users' query.
        public IQueryable<aspnet_Users> GetAspnet_Users()
        {
            return this.ObjectContext.aspnet_Users;
        }

        public void InsertAspnet_Users(aspnet_Users aspnet_Users)
        {
            if ((aspnet_Users.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(aspnet_Users, EntityState.Added);
            }
            else
            {
                this.ObjectContext.aspnet_Users.AddObject(aspnet_Users);
            }
        }

        public void UpdateAspnet_Users(aspnet_Users currentaspnet_Users)
        {
            this.ObjectContext.aspnet_Users.AttachAsModified(currentaspnet_Users, this.ChangeSet.GetOriginal(currentaspnet_Users));
        }

        public void DeleteAspnet_Users(aspnet_Users aspnet_Users)
        {
            if ((aspnet_Users.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(aspnet_Users, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.aspnet_Users.Attach(aspnet_Users);
                this.ObjectContext.aspnet_Users.DeleteObject(aspnet_Users);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Folders' query.
        public IQueryable<Folder> GetFolders()
        {
            return this.ObjectContext.Folders;
        }

        public void InsertFolder(Folder folder)
        {
            if ((folder.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(folder, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Folders.AddObject(folder);
            }
        }

        public void UpdateFolder(Folder currentFolder)
        {
            this.ObjectContext.Folders.AttachAsModified(currentFolder, this.ChangeSet.GetOriginal(currentFolder));
        }

        public void DeleteFolder(Folder folder)
        {
            if ((folder.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(folder, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Folders.Attach(folder);
                this.ObjectContext.Folders.DeleteObject(folder);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Images' query.
        public IQueryable<Image> GetImages()
        {
            return this.ObjectContext.Images;
        }

        public void InsertImage(Image image)
        {
            if ((image.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(image, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Images.AddObject(image);
            }
        }

        public void UpdateImage(Image currentImage)
        {
            this.ObjectContext.Images.AttachAsModified(currentImage, this.ChangeSet.GetOriginal(currentImage));
        }

        public void DeleteImage(Image image)
        {
            if ((image.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(image, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.Images.Attach(image);
                this.ObjectContext.Images.DeleteObject(image);
            }
        }
    }
}


